package com.richfit.barcodesystem_cczt.fragments.adapters;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import java.util.List;

/**
 * @author cl 20211117
 */
public class MainPagerViewAdapter extends FragmentStateAdapter {
    private List<Fragment> mLists;

    public MainPagerViewAdapter(FragmentActivity fm) {
        super(fm);
    }

    //    public void setFragmentCount(List<String> list) {
//        this.mLists = list;
//        notifyDataSetChanged();
//    }
    public void setFragmentData(List<Fragment> list) {
        this.mLists = list;
        notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {
        return mLists != null ? mLists.size() : 0;
    }

    @NonNull
    @Override
    public Fragment createFragment(int position) {
        //这里可以通过类型控制，返回不同界面的Fragment
        return mLists.get(position);
    }
}
